package com.zc.edu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zc.edu.entity.Teacher;
import com.zc.edu.mapper.TeacherMapper;
import com.zc.edu.service.TeacherService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author cong
 * @since 2022-11-22
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

	@Override
	public Map<String, Object> getPageInfo(Page<Teacher> pageTeacher) {
		QueryWrapper<Teacher> teacherQueryWrapper = new QueryWrapper<>();
		teacherQueryWrapper.orderByDesc("id");
		this.page(pageTeacher, teacherQueryWrapper);
		List<Teacher> records = pageTeacher.getRecords();
		long total = pageTeacher.getTotal();
		long size = pageTeacher.getSize();
		long current = pageTeacher.getCurrent();
		long pages = pageTeacher.getPages();
		boolean hasNext = pageTeacher.hasNext();
		boolean hasPrevious = pageTeacher.hasPrevious();
		HashMap<String, Object> pageInfo = new HashMap<>();
		pageInfo.put("records", records);
		pageInfo.put("current", current);
		pageInfo.put("pages", pages);
		pageInfo.put("size", size);
		pageInfo.put("total", total);
		pageInfo.put("hasNext", hasNext);
		pageInfo.put("hasPrevious", hasPrevious);
		return pageInfo;
	}
}
